/*
 * Particle.java
 *
 * Created on May 26, 2007, 9:48 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pso;

import pso.Swarm;

/**
 *
 * @author greg
 */
public abstract class Particle implements ParticleInterface {
    
    protected double[] _velocity;
    protected double[] _position;
    protected double[] _prevBest;
    protected double _prevBestFit;
    
    protected Swarm _swarm;
    
    public double getBestFit() {
        return _prevBestFit;
    }
    
    public double[] getBest() {
        return _prevBest;
    }
    
    public void update(double[] nBestPos) {
        move();
        updateFitness();
        updateVelocity();
    }
    
    public void updateFitness() {
        double fitness = getFitness();
        if(_swarm.better(fitness,_prevBestFit)){
            _prevBestFit = fitness;
            _prevBest = _position;
        }
    }
    
    public void updateVelocity() {
        
    }
    
    public void move() {
        for(int i=0; i<_position.length; i++)
            _position[i] += _velocity[i];
    }
    
}
